<style type="text/css">
form div.section > label {
	width:15% !important;
}
form div.section > div {
	margin-left:20% !important;
}
form div.section input.large{
	width:100%;
	max-width:60%;
}
form div.section textarea.large{
	width:100%;
	max-width:100%;
	height: 300px;
}

</style>
<script src="<?php echo Yii::app()->getBaseUrl();?>/admin_assets/js/nicEdit.js" type="text/javascript"></script>
<script type="text/javascript">

	bkLib.onDomLoaded(function() { 
		nicEditors.allTextAreas({fullPanel : true, maxHeight : 340, width : 747});
			//nicEditors.findEditor('english_desc').setContent('');
			$("div.nicEdit-main").addClass('wordwrap');
			$("div.nicEdit-main").width(720);
	});
</script>
		
<div class="one-column">
		 <?php 
        	$action = isset($model->id) ? Yii::app()->getBaseUrl().'/admin/cms/update' : Yii::app()->getBaseUrl().'/admin/cms/add';
            $form=$this->beginWidget('CActiveForm', array(
										'id'=>'validation',
	                    				//'action'=>$action,
	                    				'htmlOptions'=>array('enctype' => 'multipart/form-data')
									)); 
		 ?>
		<div class="tab_container" >
				<div class="form">
					<p class="note">Fields with <span class="required">*</span> are required.</p>
					<div class="section">
						<label>Menu Name<span>*</span></label>
						<div>
							<?php echo $form->textField($model,'title',array('class'=>'validate[required,minSize[2],maxSize[255]] large', 'id'=>'title')); ?>
							<?php echo $form->error($model,'title'); ?>
						</div>
					</div>
					
					<div class="section">
						<label>Slug<small>To display in URL</small></label>
						<div>
							<?php echo $form->textField($model,'slug',array('class'=>'validate[minSize[2],maxSize[255]] large', 'id'=>'slug')); ?>
							<?php echo $form->error($model,'slug'); ?>
						</div>
					</div>
					
					<div class="section">
						<label>Meta Title<span>*</span></label>
						<div>
							<?php echo $form->textField($model,'meta_title',array('class'=>'validate[required, minSize[2],maxSize[255]] large', 'id'=>'meta_title')); ?>
							<?php echo $form->error($model,'meta_title'); ?>
						</div>
					</div>
					
					<div class="section">
						<label>Meta Keywords<small>Enter multiple keywords separated by comma</small></label>
						<div>
							<?php echo $form->textField($model,'meta_keywords',array('class'=>'validate[minSize[2],maxSize[255]] large', 'id'=>'meta_keywords')); ?>
							<?php echo $form->error($model,'meta_keywords'); ?>
						</div>
					</div>
					
					<div class="section">
						<label>Meta Description</label>
						<div>
							<?php echo $form->textField($model,'meta_description',array('class'=>'validate[minSize[2]] large', 'id'=>'meta_description')); ?>
							<?php echo $form->error($model,'meta_description'); ?>
						</div>
					</div>
					
					<div class="section">
						<label>Content<span>*</span><small>Use Font: OpenSans</small></label>
						<div>
						<?php echo $form->textarea($model,'content', array('id'=>'english_desc', 'class' => 'large'));?>
						</div>
					</div>
					
					<div class="section">
						<label>Top Background Color</label>
						<div>
							<?php $model->bg_color = $bgColor;?>
							<?php echo $form->textField($model,'bg_color',array('class'=>'validate[minSize[7]] large', 'id'=>'colorpickerField')); ?>
							<?php echo $form->error($model,'bg_color'); ?>
						</div>
					</div>
					
					<div class="section">
						<label>Banner Image <small>Resolution: 167 X 100<br>Type: jpg, jpeg, png</small></label>
						<div>
							<?php echo $form->fileField($model,'image',array('class'=>'fileupload large')); ?>
							<?php echo $form->error($model,'image'); ?>
							
						</div>
						<div id="show-image">
							<?php if ( !empty($model->image)):?>
								<img src="<?php echo yii::app()->getBaseUrl()?>/images/<?php echo $model->image?>" width="200" />
								<span><a href="javascript:void(0);" class="remove">Remove</a></span>
							<?php endif;?>
						</div>
					</div>
					
					<div class="section">
						<label>Banner Heading</label>
						<div>
							<?php echo $form->textField($model,'banner_heading',array('class'=>'validate[minSize[2]] large')); ?>
							<?php echo $form->error($model,'banner_heading'); ?>
						</div>
					</div>
					
					
					<div class="section">
						<label>Banner small text</label>
						<div>
							<?php echo $form->textField($model,'banner_small',array('class'=>'validate[minSize[2]] large')); ?>
							<?php echo $form->error($model,'banner_small'); ?>
						</div>
					</div>
					
					
					<div class="section">
						<label>Button text</label>
						<div>
							<?php echo $form->textField($model,'button_text',array('class'=>'validate[minSize[2]] large')); ?>
							<?php echo $form->error($model,'button_text'); ?>
						</div>
					</div>
					
					<div class="section">
						<label>Button Link</label>
						<div>
							<?php echo $form->textField($model,'button_link',array('class'=>'validate[custom[url]] large', 'id'=>'url_required')); ?>
							<?php echo $form->error($model,'button_link'); ?>
						</div>
					</div>
					
					<div class="section">
						<label>Active<span>*</span></label>
						<div>
							<?php echo $form->checkbox($model, 'status', array('id'=>'cms_active_es', 'class'=>'chkbox', 'checked'=>'checked'));?>
							<?php echo $form->error($model,'active'); ?>
						</div>
					</div>
					
					<div class="section">
						<label>&nbsp;</label>
						<div><input type="submit" name="submit" id="submit" class="uibutton" value="Submit" /></div>
					</div>
				</div><!-- form -->
			<?php $this->endWidget(); ?>
<script>
	$(document).ready(function(){
		$('#title').on('keyup', function(){
			var enTitle = $(this).val();
			var slug = enTitle.replace(/[ ]/g,'-');
			var slug = slug.replace(/[&]/g,'and');
			if(slug.charAt(slug.length-1) == '-'){
				slug = slug.substring(0, slug.length - 1);
			}
			$('#slug').val(slug.toLowerCase());
		});
		
		$('form#validation').on('submit', function(e){
			
			var english_desc = nicEditors.findEditor('english_desc').getContent();

			if(english_desc == '<br>'){
				english_desc = '';
			}

			var $result = false;

			if(jQuery.trim(english_desc) == ''){
					showError('Content field is required',2000);
					$result = false;
			} else {
					$result = true;
			}
			if ($result == true){
				loading('processing',1);
				$('form#validation').submit();
				unloading();
			}
			else {
				return false;
			}
			return false;
		});

		$('a.remove').on('click', function(){
			$.ajax({
				data:'id=<?php echo $model->id;?>&image=<?php echo $model->image?>',
				url: '<?php echo yii::app()->getBaseUrl()?>/admin/cms/removeImage',
				type: 'get',
				success: function(resp){
					if (resp == 'success'){
						$('#show-image').remove();
					}
				}
			});
		});
			
	});
</script>
<style>
	.remove{
		float: right;
	    font-size: 14px;
	    margin-right: 285px;
	    margin-top: 20px;
	}
</style>
